﻿#pragma once

#include "common.h"
#include "ext.h"
//#include "seqbase/graphics.h"

namespace anip
{
	namespace audio
	{
		class WaveformPrimitive
		{
		private:
			Waveform& _wave;
			Playback* _play = nullptr;
			int _pos = 0, _ppos = 0;
			double volume = 1;

		public:
			WaveformPrimitive(Waveform& wav) : _wave(wav) {}

			bool presentationMode = false;

			void onActivate()
			{
				if (presentationMode && _play != nullptr)
				{
					if (!_play->stopped())
						_play->stop();
					delete _play;
					_play = nullptr;
				}

				if (_play == nullptr)
					_play = Mixer::addSound(*_wave.instantiate(), volume);
				else
					_play->unpause();
			}

			void onDeactivate()
			{
				if (!_play->stopped())
					_play->pause();
			}

			void setTime(float t, float rate)
			{
				if (!presentationMode)
					_play->setTimePosition(t / rate);
			}

			/*void render(const Viewpoint& view)
			{
				
			}*/
		};
	}
}